package com.atguigu.tingshu.order.api;

import com.atguigu.tingshu.common.anno.GuiguLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.order.OrderInfo;
import com.atguigu.tingshu.order.service.OrderInfoService;
import com.atguigu.tingshu.vo.order.OrderInfoVo;
import com.atguigu.tingshu.vo.order.TradeVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Tag(name = "订单管理")
@RestController
@RequestMapping("api/order/orderInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class OrderInfoApiController {

	@Autowired
	private OrderInfoService orderInfoService;


@GuiguLogin
	@Operation(summary = "进入结算页面")
	@PostMapping(value = "/trade")
	public Result<OrderInfoVo> trade(@RequestBody TradeVo tradeVo) {
		OrderInfoVo orderInfoVo = orderInfoService.trade(tradeVo) ;
		return Result.ok(orderInfoVo) ;
	}

	@GuiguLogin
	@Operation(summary = "提交订单")
	@PostMapping("submitOrder")
	public Result<Map<String, Object>> submitOrder(@RequestBody @Validated OrderInfoVo orderInfoVo) {
		String orderNo = orderInfoService.submitOrder(orderInfoVo);
		Map<String, Object> map = new HashMap<String , Object>();
		map.put("orderNo", orderNo);
		return Result.ok(map);
	}

	@GuiguLogin
	@Operation(summary = "根据订单号获取订单信息")
	@GetMapping("/getOrderInfo/{orderNo}")
	public Result<OrderInfo> getOrderInfo(@PathVariable String orderNo) {
		OrderInfo orderInfo = orderInfoService.getOrderInfoByOrderNo(orderNo);
		return Result.ok(orderInfo);
	}

	@GuiguLogin
	@Operation(summary = "获取用户订单")
	@GetMapping(value = "/findUserPage/{page}/{limit}")
	public Result<IPage<OrderInfo>> findOrderInfoByPage(@PathVariable(value = "page") Integer pageNo , @PathVariable(value = "limit") Integer pageSize) {
		IPage<OrderInfo> infoIPage = orderInfoService.findOrderInfoByPage(pageNo , pageSize) ;
		return Result.ok(infoIPage) ;
	}
}

